import {
  Message
} from 'element-ui'
var verification = {

  numberCheck(rule, value, callback) {
    // 整数和小数
    var reg = /^(([^0][0-9]+|0)\.([0-9]{1,2})$)|^(([^0][0-9]+|0)$)|^(([1-9]+)\.([0-9]{1,2})$)|^(([1-9]+)$)/;
    let pattern = new RegExp(reg)
    if(!pattern.test(value)) {
      callback(new Error('请输入数字'))
    }else{
      callback()
    }
  },

  validPhone(rule, value, callback) {
    let reg = /^1[34578]\d{9}$/;
    if (!reg.test(value)) {
      callback(new Error('手机号码必须为11为数字'))
    } else {
      callback()
    }
  },
  userNameCode(classVal) {
    var reg = /^[a-z0-9A-Z\u2E80-\u9FFF]{1,14}$/;
    if (!reg.test(classVal)) {
      return "请输入由1-14位英文，数字，汉字的姓名";
    } else {
      return true;
    }
  },
  passwordCode(classVal) {
    var regs = /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,32}$/;
    //var regs = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,32}$/;
    if (!regs.test(classVal)) {
      return "请输入6-32 位字符，不能与用户名相同，且字母、数字、符号至少包含两种的密码";
    } else {
      return true;
    }
  },
  telphoneCode(classVal) {
    if (!(/^1[34578]\d{9}$/.test(classVal))) {
      return "请输入正确电话号码";
    } else {
      return true;
    }
  },
  emailCode(data) {
    if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(data)) && data !== "") {
      return "请输入正确邮箱号码";
    } else {
      return true;
    }
  },
  spaceCode(classVal) {
    var regy = /\s/g;
    if (regy.test(classVal)) {
      return "不能输入空格";
    } else {
      return true;
    }
  },
  specialCode(classVal) {
    var reg = /[\@\/\'\\\"#$%&\^\*]/g;
    if (reg.test(classVal)) {
      return "不能输入特殊字符(@/'\"#$%&^*)";
    } else {
      return true;
    }
  },
  passwordTrue(data) {
    if (data[1] !== data[0]) {
      return "两次密码输入不一致";
    } else {
      return true;
    }
  },
  emptyCode(data, message) {
    if (data === "") {
      return message + "不能为空";
    } else {
      return true;
    }
  },
  optionCode(data, message) {
    console.log(data)
    if (data === "") {
      return "请选择" + message;
    } else {
      return true;
    }
  },
  oploadCode(data, message) {
    if (data === "") {
      return "请上传" + message;
    } else {
      return true;
    }
  },
  formatDate(now) {
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();

    return year + "-" + month + "-" + date + "   " + hour + ":" + minute;
  },
  proving(veri_lon) {
    var veri = this;
    var bool = true;
    verFun: {
      for (let i in veri_lon) {
        let types = veri_lon[i].type;
        for (let j in types) {
          let result = veri[types[j]](veri_lon[i].data, veri_lon[i].name);

          if (result !== true) {

            Message({
              message: result,
              type: 'error'
            });
            bool = false;
            break verFun;
          }
        }
      }
    }
    return bool;

  },
  print(e, f, g) {
    let num = g;
    var loadCard = (e, f) => {

      let headKey = [];
      let headData = "";
      let w = (o) => {
        console.log(headStr)
        console.log(o)
        let headStr = "";
        let shamData = [];
        let b = false;
        for (let i of o) {

          if (i.datas) {
            headStr += "<th colspan=" + i.datas.length + ">" + i.name + "</th>";
            b = true;
            shamData = shamData.concat(i.datas);
          } else {
            headStr += "<th rowspan=" + num + ">" + i.name + "</th>";
            headKey.push(i["key"]);

          }

        }
        num--;
        headData += "<tr>" + headStr + "</tr>";
        if (b) {

          w(shamData)
        }
      }
      w(e);
      let trStr = "";
      for (let j of f) {
        let tdStr = "";
        for (let i of headKey) {
          tdStr += "<td>" + ((j[i] || j[i] == 0) ? j[i] : "") + "</td>";
        }
        trStr += "<tr>" + tdStr + "</tr>";
      }
      return (
        '<table style="width:90%;margin:0 auto;box-sizing:border-box;color:#000;text-align:center;" border="1">' +
        headData +
        trStr +
        "</table>"
      );
    };

    window.document.body.innerHTML = loadCard(e, f);


    setTimeout(() => {
      window.print();
      location.reload();
    }, 800);

  }

};
export default verification;
